package com.bhatni.mockprocessor.macro;

import com.bhatni.mockprocessor.Message;
import com.bhatni.mockprocessor.macro.BaseMacro;
import java.util.Properties;
import java.util.Random;

/**
 * Generates a random number as Macro value. The Value parameter specifies to number of digits to generate.
 */
public class RandomNumber extends BaseMacro {
    int digits;

    @Override
    public void setValue(String value) {
        digits = Integer.parseInt(value);
    }

    @Override
    public String getResolvedValue(Message in) {
        return generateRandomNum(digits);
    }

    private String generateRandomNum(int length) {
        Random rnd = new Random(System.currentTimeMillis());
        StringBuilder strBuf = new StringBuilder();
        for (int i = 0; i < length; i++) {
            strBuf.append(rnd.nextInt(10));
        }
        return strBuf.toString();
    }



}
